package com.guli.statistics.controller.admin;


import com.guli.common.vo.R;
import com.guli.statistics.service.DailyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 网站统计日数据 前端控制器
 * </p>
 *
 * @author Frank
 * @since 2019-04-22
 */
@Api(tags = "统计信息接口")
@RestController
@CrossOrigin
@RequestMapping("/admin/statistics/daily")
public class DailyAdminController {
    @Autowired
    private DailyService dailyService;

    @GetMapping("{day}")
    @ApiOperation(value = "创建统计信息")
    public R createStatisticsByDate(@ApiParam(value = "统计日期", name = "day", example = "2019-01-01")
                                    @PathVariable("day") String day) {
        Boolean result = dailyService.createStatisticsByDay(day);

        return result ? R.ok().message("统计成功") : R.error().message("统计失败");
    }

    @ApiOperation(value = "查询统计信息")
    @GetMapping("/show-chart/{begin}/{end}/{type}")
    public R showChart(
            @ApiParam(value = "统计开始日期", name = "begin") @PathVariable("begin") String begin,
            @ApiParam(value = "统计结束日期", name = "end") @PathVariable("end") String end,
            @ApiParam(value = "统计类型（统计项）", name = "type") @PathVariable("type") String type

    ) {
        Map<String, Object> map  = dailyService.getChartData(begin, end, type);
        return R.ok().data(map);
    }
}

